IF EQUALP :PRINT "NEWKEY [ANALYZE :SENTENCE BF :KEYWORDS STOP]
IF WORDP :PRINT [CHECKRULES :PRINT GPROP :PRINT "RULES STOP]
IF EQUALP FIRST :PRINT "PRE ~
[ANALYZE RECONSTRUCT FIRST BF :PRINT BF BF :PRINT STOP]
PRINT RECONSTRUCT :PRINT
MEMORY :KEYWORD :SENTENCE
END
TO FAMILYP :WORD
OUTPUT NOT EMPTYP GPROP :WORD "FAMILY
END
TO GETSENTENCE :TEXT
MAKE "KEYWORDS []
OUTPUT GETSENTENCE1 :TEXT []
END
TO GETSENTENCE1 :TEXT :OUT
IF EMPTYP :TEXT [OUTPUT :OUT]
IF EQUALP FIRST :TEXT ". ~
[IFELSE EMPTYP :KEYWORDS ~
[OUTPUT GETSENTENCE1 BF :TEXT []] [OUTPUT :OUT]]
CHECKPRIORITY FIRST :TEXT
OUTPUT GETSENTENCE1 BF :TEXT SE :OUT TRANSLATE FIRST :TEXT
END
TO GETSTUFF :STUFF
LOCAL "LINE
MAKE "LINE RL
IF EMPTYP :LINE [OP :STUFF]
OP GETSTUFF SE :STUFF :LINE
END
TO IN :WORD
OP MEMBERP :WORD :IN.LIST
END
TO LASTRESORT
PRINT FIRST :LASTRESORT
MAKE "LASTRESORT LPUT FIRST :LASTRESORT BF :LASTRESORT
END
TO LOOP
MAKE "TEXT TOKENIZE GETSTUFF []
MAKE "SENTENCE GETSENTENCE :TEXT
ANALYZE :SENTENCE :KEYWORDS
PRINT []
LOOP
END
TO MATCH :PAT :SEN
LOCAL [SPECIAL.VAR SPECIAL.PRED SPECIAL.BUFFER IN.LIST]
IF OR WORDP :PAT WORDP :SEN [OP "FALSE]
IF EMPTYP :PAT [OP EMPTYP :SEN]
IF LISTP FIRST :PAT [OP SPECIAL FPUT "!: :PAT :SEN]
IF MEMBERP FIRST FIRST :PAT [? # ! & @] [OP SPECIAL :PAT :SEN]
IF EMPTYP :SEN [OP "FALSE]
IF EQUALP FIRST :PAT FIRST :SEN [OP MATCH BF :PAT BF :SEN]
OP "FALSE
END
TO MATCH!
IF EMPTYP :SEN [OP "FALSE]
IF NOT TRY.PRED [OP "FALSE]
MAKE :SPECIAL.VAR FIRST :SEN
OP MATCH BF :PAT BF :SEN
END
TO MATCH#
MAKE :SPECIAL.VAR []
OP #TEST #GATHER :SEN
END
TO MATCH&
OP &TEST MATCH#
END
TO MATCH?
MAKE :SPECIAL.VAR []
IF EMPTYP :SEN [OP MATCH BF :PAT :SEN]
IF NOT TRY.PRED [OP MATCH BF :PAT :SEN]
MAKE :SPECIAL.VAR FIRST :SEN
IF MATCH BF :PAT BF :SEN [OP "TRUE]
MAKE :SPECIAL.VAR []
OP MATCH BF :PAT :SEN
END
TO MATCH@
MAKE :SPECIAL.VAR :SEN
OP @TEST []
END
TO MEMORY :KEYWORD :SENTENCE
LOCAL [RULES RULE NAME]
MAKE "RULES GPROP :KEYWORD "MEMR
IF EMPTYP :RULES [STOP]
IF NOT MATCH FIRST :RULES :SENTENCE [STOP]
MAKE "NAME LAST :RULES
MAKE "RULES GPROP :KEYWORD :NAME
MAKE "RULE FIRST :RULES
PPROP :KEYWORD :NAME LPUT :RULE BF :RULES
MAKE "MEMORY FPUT RECONSTRUCT :SENTENCE :MEMORY
END
TO NORULES
IFELSE :MEMFLAG [USEMEMORY] [LASTRESORT]
MAKE "MEMFLAG NOT :MEMFLAG
END
TO PARSE.SPECIAL :WORD :VAR
IF EMPTYP :WORD [OP LIST :VAR "ALWAYS]
IF EQUALP FIRST :WORD ": [OP LIST :VAR BF :WORD]
OP PARSE.SPECIAL BF :WORD WORD :VAR FIRST :WORD
END
TO QUOTED :THING
IF LISTP :THING [OP :THING]
OP WORD "" :THING
END
TO RECONSTRUCT :SENTENCE
IF EMPTYP :SENTENCE [OUTPUT []]
IF NOT EQUALP ": FIRST FIRST :SENTENCE ~
[OUTPUT FPUT FIRST :SENTENCE RECONSTRUCT BF :SENTENCE]
OUTPUT SE REWORD FIRST :SENTENCE RECONSTRUCT BF :SENTENCE
END
TO REWORD :WORD
IF MEMBERP LAST :WORD [. ? ,] [OUTPUT ADDPUNCT REWORD BL :WORD LAST :WORD]
OUTPUT THING BF :WORD
END
TO SET.IN
MAKE "IN.LIST FIRST BF :PAT
MAKE "PAT FPUT FIRST :PAT BF BF :PAT
END
TO SET.SPECIAL :LIST
MAKE "SPECIAL.VAR FIRST :LIST
MAKE "SPECIAL.PRED LAST :LIST
IF EMPTYP :SPECIAL.VAR [MAKE "SPECIAL.VAR "SPECIAL.BUFFER]
IF MEMBERP :SPECIAL.PRED [IN ANYOF] [SET.IN]
IF NOT EMPTYP :SPECIAL.PRED [STOP]
MAKE "SPECIAL.PRED FIRST BF :PAT
MAKE "PAT FPUT FIRST :PAT BF BF :PAT
END
TO SPECIAL :PAT :SEN
SET.SPECIAL PARSE.SPECIAL BF FIRST :PAT "
OP RUN FPUT WORD "MATCH FIRST FIRST :PAT []
END
TO TOKENIZE :TEXT
IF EMPTYP :TEXT [OUTPUT []]
OUTPUT SE TOKENWORD FIRST :TEXT " TOKENIZE BF :TEXT
END
TO TOKENWORD :WORD :OUT
IF EMPTYP :WORD [OUTPUT :OUT]
IF MEMBERP FIRST :WORD [, " ] [OUTPUT TOKENWORD BF :WORD :OUT]
IF MEMBERP FIRST :WORD [. ? ! |;|] [OUTPUT SE :OUT ".]
OUTPUT TOKENWORD BF :WORD WORD :OUT FIRST :WORD
END
TO TRANSLATE :WORD
LOCAL "NEW
MAKE "NEW GPROP :WORD "TRANSLATION
OUTPUT IFELSE EMPTYP :NEW [:WORD] [:NEW]
END
TO TRY.PRED
IF LISTP :SPECIAL.PRED [OP MATCH :SPECIAL.PRED FIRST :SEN]
OP RUN LIST :SPECIAL.PRED QUOTED FIRST :SEN
END
TO USEMEMORY
IF EMPTYP :MEMORY [LASTRESORT STOP]
PRINT FIRST :MEMORY
MAKE "MEMORY BF :MEMORY
END
Make "gensym.number 80
Make "lastresort [[I AM NOT SURE I UNDERSTAND YOU FULLY.] [PLEASE GO ON.] [WHAT DOES THAT SUGGEST TO YOU?] [DO YOU FEEL STRONGLY ABOUT DISCUSSING SUCH THINGS?]]
Make "memflag "FALSE
Pprop "alike "RULES [DIT]
Pprop "alike "PRIORITY 10
Pprop "always "g69 [[CAN YOU THINK OF A SPECIFIC EXAMPLE?] [WHEN?] [WHAT INCIDENT ARE YOU THINKING OF?] [REALLY, ALWAYS?] [WHAT IF THIS NEVER HAPPENED?]]
Pprop "always "RULES [[#] g69]
Pprop "always "PRIORITY 1
Pprop "am "g19 [[WHY DO YOU SAY "AM"?] [I DON'T UNDERSTAND THAT.]]
Pprop "am "g18 [[DO YOU BELIEVE YOU ARE :STUFF?] [WOULD YOU WANT TO BE :STUFF?] [YOU WISH I WOULD TELL YOU YOU ARE :STUFF.] [WHAT WOULD IT MEAN IF YOU WERE :STUFF?] HOW]
Pprop "am "RULES [[# ARE YOU #STUFF] g18 [#] g19]
Pprop "am "TRANSLATION "ARE
Pprop "am "PRIORITY 0
Pprop "are "g24 [[DID YOU THINK THEY MIGHT NOT BE :STUFF?] [WOULD YOU LIKE IT IF THEY WERE NOT :STUFF?] [WHAT IF THEY WERE NOT :STUFF?] [POSSIBLY THEY ARE :STUFF.]]
Pprop "are "g23 [HOW]
Pprop "are "g22 [[WHY ARE YOU INTERESTED IN WHETHER I AM :STUFF OR NOT?] [WOULD YOU PREFER IF I WEREN'T :STUFF?] [PERHAPS I AM :STUFF IN YOUR FANTASIES.] [DO YOU SOMETIMES THINK I AM :STUFF?] HOW]
Pprop "are "g21 [[WHAT MAKES YOU THINK THERE ARE :STUFF?] [DO YOU USUALLY CONSIDER :STUFF?] [DO YOU WISH THERE WERE :STUFF?]]
Pprop "are "g20 [[PRE [:A THERE ARE :B] ARE]]
Pprop "are "RULES [[#A THERE ARE #B YOU #C] g20 [# THERE ARE &STUFF] g21 [# ARE I #STUFF] g22 [ARE #] g23 [# ARE #STUFF] g24]